<?php
use EasyWeChat\Factory;
$wid = Session::get("wid");
$domain=$_SERVER['HTTP_HOST'];
$agency=new Model('user_agency');
$agency->find(array('domain'=>$domain));
$key_word=$agency->key_word;//网站关键词
$describe=$agency->describe;//网站描述
$email=$agency->email;//email
$phone=$agency->telephone;//联系电话 
$qq=$agency->kfcode;//QQ
$logo=$agency->logo;//logo
$webname=$agency->webname;//网站名称
$webtitle=$agency->webtitle;//网站标题
$company_name=$agency->company_name;//公司名称
$company_address=$agency->company_address;//公司地址
$record_number=$agency->record_number;//备案号
$qr_code=$agency->qr_code;//二维码
$menuManage = (new Model('pc_menu_manage'))->where(['pid'=>$agency->id,'display'=>1])->list_all_array();
// $menu = json_decode($menuManage->menu,1);
$slideManage = (new Model('pc_slide_manage'))->where(['pid'=>$agency->id])->order('sort')->list_all();
if(!count($slideManage) && !$agency->isadmin){
	$admin = (new Model('user_agency'))->find(['isadmin'=>1]);
	$slideManage = (new Model('pc_slide_manage'))->where(['pid'=>$admin->id])->order('sort')->list_all();
}
$lxkefu = (new Model('qy_kefu'))->find(['mid' => $agency->id]);
$switch=$agency->switch_pc;
if($switch==1){
	$thirdappsetting=(new Model('qy_agency_thirdappsetting'))->find(['pid'=>$agency->id]);
	$config = [
	    'corp_id'          => $thirdappsetting->corpid?$thirdappsetting->corpid:'',
	    'secret'           => $thirdappsetting->providerSecret?$thirdappsetting->providerSecret:'',
	    'suite_id'         => $thirdappsetting->suite_id?$thirdappsetting->suite_id:'',
	    'suite_secret'     => $thirdappsetting->suite_secret?$thirdappsetting->suite_secret:'',
	    'token'            => $thirdappsetting->token?$thirdappsetting->token:'',
	    'aes_key'          => $thirdappsetting->encodingAESKey?$thirdappsetting->encodingAESKey:'',
	    'reg_template_id'  => $thirdappsetting->template_id?$thirdappsetting->template_id:'',
	];
	try{
		$app = Factory::openWork($config);
		$RegisterCode = $app->provider->getRegisterCode();
		$RegisterUrl = "https://open.work.weixin.qq.com/3rdservice/wework/register?register_code={$RegisterCode['register_code']}";
	}catch (Exception $e) {

	}
	Page::view('moban/index');
}else{
// 	$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
// // return  $http_type.$_SERVER['SERVER_NAME'];
$fission = (new Model("qy_fission"))->where(["paohui_link@!~"=>$_SERVER['HTTP_HOST']])->field("id")->get_model_array();
if($fission["id"]){
  echo "炮灰域名禁止访问！";die;
}
Redirect::to('/login');	
}
